package top.saplf.sileny

import android.app.Application
import io.realm.Realm
import io.realm.RealmConfiguration
import timber.log.Timber.*
import top.saplf.sileny.base.ui.SilenyActivityCallbacks


/**
 * @author Saplf on 17/3/4
 */
class SilenyApplication : Application() {

    companion object {
        private lateinit var tmpApp: SilenyApplication
        val app by lazy { tmpApp }
    }

    override fun onCreate() {
        super.onCreate()

        // init static application instance
        tmpApp = this

        // register basic activity operations
        registerActivityLifecycleCallbacks(SilenyActivityCallbacks)

        // open timber's debug option on debug mode
        if (BuildConfig.DEBUG) {
            plant(DebugTree())
        }

        // init realm database
        Realm.init(this)
        val config = RealmConfiguration.Builder().build()
        Realm.setDefaultConfiguration(config)
    }
}